package cn.edu.nks.util;

import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

import com.mchange.v2.c3p0.ComboPooledDataSource;

/**
 * 数据库连接提供者
 * @author wangbs
 *
 */
public class DBConnectProvider {
	private static DataSource dataSource = null;
	
	static{
		dataSource = new ComboPooledDataSource();		
	}
	/**
	 * 从连接池获取数据库连接
	 * @return
	 */
	public static Connection getConnection(){
		Connection con = null;
		try {
			con = dataSource.getConnection();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return con;
	}
	
	/**
	 * 释放数据库连接
	 */
	public static void freeConnection(Connection con){
		
		try {
			if(con != null){
				con.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
}
